﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>盘点报告</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>

</head>
<body>
    <div class="layui-fluid">
        <div id="bDiv">
        </div>
        <div class="layui-card">
            <div class="layui-card-body" style="margin-top:5px">
                <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="venCode" placeholder="盘点单号" autocomplete="off" class="layui-input" id="venCode">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="erpCode" placeholder="关联单号" autocomplete="off" class="layui-input" id="erpCode">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="wareName" placeholder="仓库名称" autocomplete="off" class="layui-input" id="wareName">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="positionName" placeholder="货位名称" autocomplete="off" class="layui-input" id="positionName">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="erpProCode" placeholder="存货编码" autocomplete="off" class="layui-input" id="erpProCode">
                    </div>
                    <div class="layui-inline layui-show-xs-block">
                        <input type="text" name="proName" placeholder="存货名称" autocomplete="off" class="layui-input" id="proName">
                    </div>
                </form>
            </div>
            <div>
                <span style="margin-left: 20px; padding: 7px; background-color: #C3FDB8; font-size: Xx-small">已同步</span>
            </div>

            <div class="layui-card-body layui-table-body layui-table-main" id="layui-table-main">
                <table class="layui-hide" id="list" lay-filter="list"></table>
            </div>

        </div>

    </div>
</body>

</html>

<script>
    var webCode = "";
    var pchCodes = "";
    var isSync = "";
    var pdType = "";//盘点类型

     $(function () {
        webCode = getUrlVariable("menuCode");
        BannerData(webCode, "bDiv");

        loadData();
    })

    //var ids = "";
    function loadData() {
        layui.use('table', function () {
            var conditon = JSON.stringify(FormToJson("qForm"));
            var table = layui.table;
            table.render({
                elem: '#list'
            , cols: [[ //标题栏
                { type: 'checkbox' }
                , { field: 'venCode', align: 'center', title: '盘点单号', width: 110 }
                    , { field: 'erpCode', align: 'center', title: '关联单号', width: 110 }
                    , { field: 'wareName', align: 'center', title: '盘点仓库', width: 110 }
                // , { field: 'positionName', align: 'center', title: '盘点货位', width: '7%'  }
                // , { field: 'proName', align: 'center', title: '存货名称', width: '10%'  }
                // , { field: 'spec', align: 'center', title: '规格', width: '6%'  }
                    , { field: 'erpNumber', align: 'center', title: '用友账面数', width: 110 }
                    , { field: 'ypNum', align: 'center', title: '物控账面数', width: 110, style: "color:blue", event: 'ypDone' }
                    , { field: 'ypCount', align: 'center', title: '应盘件数', width: 100, style: "color:blue", event: 'ypDone' }
                , { field: 'spNum', align: 'center', title: '实盘数', width: 110, style: "color:blue", event: 'spDone'}
                    , { field: 'spCount', align: 'center', title: '实盘件数', width: 100, style: "color:blue", event: 'spDone' }
                    , { field: 'pyNum', align: 'center', title: '盘盈数', width: 110, style: "color:blue", event: 'pyDone' }
                , { field: 'pyCount', align: 'center', title: '盘盈件数', width: 100, style: "color:blue", event: 'pyDone' }
                    , { field: 'pkNum', align: 'center', title: '盘亏数', width: 110, style: "color:blue", event: 'pkDone' }
                    , { field: 'pkCount', align: 'center', title: '盘亏件数', width: 100, style: "color:blue", event: 'pkDone' }
            ]], done: function (res, curr, count) {
                $("[data-field='id']").css('display', 'none');//隐藏列
                $.each(res['data'], function (i, j) {
                    if (j['isSync'] == "1") {
                        TableRowColor('layui-table-main', i, '#C3FDB8');//已同步
                    }
                });
            }

            , url: "../ProCheck/GetDataList?dataType=report&condition=" + conditon
            , skin: 'row' //表格风格
             ,loading:true
            , even: true
            , page: true //是否显示分页
            , limits: [20, 30, 50]
            , limit: 15 //每页默认显示的数量
            , id: "tData"
            });

            //监听工具条 多选框
            table.on('checkbox(list)', function (obj) {
                var checkStatus = table.checkStatus('tData');
                pchCodes = ""; isSync = ""; pdType = ""; //ids = "";
                for (var i = 0; i < checkStatus.data.length; i++) {
                    pchCodes += checkStatus.data[i].pchCode + ",";
                    //ids += checkStatus.data[i].erpId + ",";
                    isSync += checkStatus.data[i].isSync + ",";
                    pdType += checkStatus.data[i].chType + ",";
                }
                pchCodes = pchCodes.substr(0, pchCodes.length - 1);
                //ids = ids.substr(0, ids.length - 1);
                isSync = isSync.substr(0, isSync.length - 1);
            });

            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event === 'ypDone') {
                    InfoOpenPage('../ProCheck/CheckTaskList?dataType=chyp&pchCode=' + data.venCode, data.erpCode + "-应盘清单", "80%", "90%");
                } else if (obj.event == 'spDone') {
                    InfoOpenPage('../ProCheck/TaskRecords?pchCode=' + data.pchCode, data.erpCode +"-实盘清单", "80%", "90%");
                } else if (obj.event == 'pyDone') {
                    // if (userPower.indexOf("pchDochanage") >= 0) {
                        detail(data.pchCode, "Bar", "1", data.erpCode + "-盘盈");
                    // } 
                    
                } else if (obj.event == 'pkDone') {
                    // if (userPower.indexOf("pchDochanage") >= 0) {
                        detail(data.pchCode, "Bar", "0", data.erpCode + "-盘亏");
                    // } 
                }
            });

        });
    }

    function detail(pchCode, barType, ykType, title) {
        var url = '../ProCheck/checkReportResult?barType=' + barType + '&types=' + ykType + '&pchCode=' + pchCode;
        InfoOpenPage(url, title, "80%", "90%");
    }
   
 
    /**
取消报告（删除）
**/
    function delReport() {
        if (!isSync.trim(',').includes("1")) {
            if (pchCodes != "") {
                $.ajax({
                    url: "../ProCheck/delReport",
                    data: { pchCodes: pchCodes },
                    dataType: "json",
                    type: "POST",
                    async: false,
                    success: function (data) {
                        if (data.result) {
                            layer.msg("盘点报告已取消", { icon: 1 });
                            loadData();
                        } else {
                            layer.msg(data.message, { icon: 2 });
                        }
                    }
                });
            }
            else {
                layer.msg("请先盘点报告", { icon: 2});
            }
        }
        else {
            layer.msg("选中数据存在已同步结果的数据，不允许取消报告！", { icon: 2}); return;
        }
    }

    /**
同步结果
**/
    function syncReport()
    {

        if (!isSync.trim(',').includes("1")) {
            if (pchCodes != "") {
                $.ajax({
                    url: "../ProCheck/syncReport",
                    //data: { ids: ids, pchCodes: pchCodes },
                    data: {  pchCodes: pchCodes },
                    dataType: "json",
                    type: "POST",
                    async: false,
                    success: function (data) {
                        if (data.result) {
                            layer.msg("结果已同步", { icon: 1 });
                            loadData();
                        } else {
                            layer.msg(data.message, { icon: 2 });
                        }
                    }
                });
            } else {
                layer.msg("请先选择要同步的盘点报告", { icon: 2 });
            }
        }
        else {
            layer.msg("选中数据存在已同步结果的数据，不允许再次同步！", { icon: 2 }); return;
        }
    }

</script>